package com.kaiyun.sharding;

import com.kaiyun.sharding.mapper.CourseBaseMapper;
import com.kaiyun.sharding.model.CourseBase;
import com.kaiyun.sharding.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试多库多表的情况
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class ShardingApplicationTests2 {

    @Autowired
    private CourseBaseMapper courseBaseMapper;

    @Autowired
    private CourseBaseService courseBaseService;

    /**
     * 单个插入courseBase
     */
    @Test
    public void insertOneCourseBase(){
        for (int i = 0; i <10 ; i++) {
            CourseBase cc=new CourseBase();
            cc.setName("姓22名"+i);
            cc.setUserId((long)i);
            courseBaseMapper.insert(cc);
        }
    }


    /**
     * 批量插入courseBase
     */
    @Test
    public void batchInsertCourseBase(){
        List<CourseBase> list=new ArrayList<>();

        for (int i = 0; i <50 ; i++) {
            CourseBase cc=new CourseBase();
            cc.setName("批量"+i);
            cc.setUserId((long)i);
            list.add(cc);
        }
        courseBaseService.saveBatch(list);
    }

    @Test
    public void getDetail() {
        CourseBase c=new CourseBase();
        CourseBase courseBase = courseBaseMapper.selectById(1333318970232074241L);

        log.info(courseBase.toString());
    }



}
